//index.js
//获取应用实例
const app = getApp()


Page({

  /**
   * 页面的初始数据
   */
  data: {
    getBar: app.data.url + 'zhongxue/teacher/getbanner',
    getshouquan: app.data.url +'zhongxue/teacher/shouquan',
    getshijuanUrl: app.data.url + 'zhongxue/teacher/syhongdian',
    berUrl:[
      "/img/8.png"
    ],
    shuju:'',
    playUrl:[
      { name: "课程表", url: app.data.url +"uploads/laoshi/40.png", urls:"kechengbiao"},
      { name: "学生评价", url: app.data.url +"uploads/laoshi/41.png", urls: "student"},
      { name: "布置作业", url: app.data.url +"uploads/laoshi/42.png", urls: "arrangement"},
      { name: "老师通知", url: app.data.url +"uploads/laoshi/43.png", urls: "message"},
      { name: "试卷评价", url: app.data.url +"uploads/laoshi/44.png", urls: "evaluate"},
      { name: "备忘录", url: app.data.url +"uploads/laoshi//45.png", urls: "backup"}
    ],
    pid: 0,
    userInfo:{},
    status:true,
    hongdian:[],
  },
  
  //课程表跳转
  kechengb:function(){
    var user = wx.getStorageSync('newuser')
    if(!user){
      wx.navigateTo({
        url: '/pages/register/register',
      })
    }else{
      wx.navigateTo({
        url: '/pages/kechengbiao/kechengbiao',
      })
    }
  },
  //学生评价
  pinjia:function(){
    var user = wx.getStorageSync('newuser')
    if (!user) {
      wx.navigateTo({
        url: '/pages/register/register',
      })
    }else{
      wx.navigateTo({
        url: '/pages/student/student',
      })
    }
  },
  //布置作业
  zuoye: function () {
    var user = wx.getStorageSync('newuser')
    if (!user) {
      wx.navigateTo({
        url: '/pages/register/register',
      })
    }else{
      wx.navigateTo({
        url: '/pages/arrangement/arrangement',
      })
    }
  },
  //老师通知
  tongzhi: function () {
    var user = wx.getStorageSync('newuser')
    if (!user) {
      wx.navigateTo({
        url: '/pages/register/register',
      })
    } else {
      wx.navigateTo({
        url: '/pages/message/message',
      })
    }
  },
  //试卷评价
  shijuan: function () {
    var user = wx.getStorageSync('newuser')
    if (!user) {
      wx.navigateTo({
        url: '/pages/register/register',
      })
    } else {
      wx.navigateTo({
        url: '/pages/evaluate/evaluate',
      })
    }
  },
  //备忘录
  beiwang:function(){
    var user = wx.getStorageSync('newuser')
    if (!user) {
      wx.navigateTo({
        url: '/pages/register/register',
      })
    } else {
      wx.switchTab({
        url: '/pages/backup/backup',
      })
    }
  },

  getUsers:function(e){
    // console.log(e);
    if (e.detail.errMsg =="getUserInfo:ok"){
      var userinfo = e.detail.userInfo;
      var that = this;
      // console.log(userinfo);
      wx.login({
        success:function(ress){
          var code = ress.code;
          userinfo.code = code;
          console.log(userinfo);
          wx.request({
            url: that.data.getshouquan,
            data:userinfo,
            method:'post',
            success:function(res){
              // console.log(res);
              var user = res.data;
              // console.log(user);
              if(user.code == 200){
                wx.setStorageSync('user', user.data);
                that.setData({ status:true})
              }else{
                wx.showToast({
                  title: data.msg,
                  icon: 'none'
                })
              }
            }
          })
        }
      })
    }else{
      console.log('选择取消')
    }

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSetting({
      success: function(res) {
        // console.log(res);
        if (res.authSetting["scope.userInfo"]){
          that.setData({ status:true})
        }else{
          that.setData({ status: false })
        }
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  },
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this;
    var user = wx.getStorageSync('newuser');
    var token = user.token;
    var shenhe = user.shenhe;
    var hongdian = that.data.hongdian;
    // console.log(that)
    wx.request({
      url: that.data.getBar,
      method:'post',
      success:function(res){
        var data=res.data
        var shuju=data.data.img
        // console.log(data)
        if(data.code==200){
          // console.log(shuju);
          that.setData({ shuju:shuju});
        }else{
          wx.showToast({
            title: '获取失败',
            icon: 'none',
          })
        }
      }
    })

    wx.request({
      url: that.data.getshijuanUrl,
      method:'post',
      data:{token:token,shenhe:shenhe},
      success:function(res){
        var data = res.data;
        // console.log(data);
        if(data.code == 200){
          var hongdian = data.data.data;
          console.log(hongdian)
          that.setData({ hongdian: hongdian})
        }else{
          console.log('获取失败')
        }
        
      }
    })

    var user = wx.getStorageSync('user');
    console.log(user);
    if (!user) {
      this.setData({ status: false });
    }

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("hahah")
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})